package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.glres;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.api.common.enums.DictConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author liwei
 * 资源管理-用户资源管理
 */
@Data
@Entity
@Table(name = "t_glsc_user_resource")
@org.hibernate.annotations.Table(appliesTo = "t_glsc_user_resource", comment = "资源管理-用户资源管理")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Where(clause = "deleted = 'N'")
@SQLDelete(sql = "update t_glsc_user_resource set deleted = 'Y' where id=?")
@SQLDeleteAll(sql = "update t_glsc_user_resource set deleted = 'Y' where id=?")
public class GlscUserResource implements Serializable {
    private static final long serialVersionUID = 4152764785001941927L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition = "int(20) comment '用户资源id'")
    private Integer id;

    @ApiModelProperty(value = "资源名称")
    @Column(name = "name", columnDefinition = "varchar(255) COMMENT '资源名称'")
    private String name;

    @ApiModelProperty(value = "办公地址 ")
    @Column(name = "address", columnDefinition = "varchar(255) COMMENT '办公地址 数据字典t_user_res_office_addr'")
    private String address;

    @ApiModelProperty(value = "备注")
    @Column(name = "memo", columnDefinition = "varchar(255) COMMENT '备注'")
    private String memo;

    @ApiModelProperty(value = "创建时间 yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", columnDefinition = "datetime comment '创建时间'", updatable = false)
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createTime;

    @Column(name = "op_time", columnDefinition = "datetime comment '更新时间'")
    @ApiModelProperty(value = "操作时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime opTime;

    @ApiModelProperty(value = "是否删除，字典 YesNo:（N=未删除(默认) Y=已删除)")
    @Column(name = "deleted", columnDefinition = "varchar(20) default 'N' COMMENT '是否删除，字典 yesno （N=否(默认) Y=是)'")
    private String deleted = DictConstant.NO;

    @Column(name = "user_id", columnDefinition = "int DEFAULT NULL COMMENT '资源管理人用户id'")
    @ApiModelProperty(value = "资源管理人用户id")
    private Long userId;

    @ApiModelProperty(value = "资源管理人用户名称 ")
    @Column(name = "user_name", columnDefinition = "varchar(255) COMMENT '资源管理人用户名称'")
    private String userName;

    @ApiModelProperty(value = "资源管理人oa账号")
    @Column(name = "user_oa_account", columnDefinition = "varchar(255) comment '资源管理人oa账号'")
    private String userOaAccount;
}
